import allure
import jsonpath
from utils.send_request import send_jdbc_request
import logging

def json_extractor(case,response,dict,index=0):
    if case["jsonExData"]:
        with allure.step("4.JSON提取"):
             for key, value in eval(case["jsonExData"]).items():
                 json_data = jsonpath.jsonpath(response.json(), value)
                 dict[key] = json_data[index]
             logging.info(f"4.JSON提取, 根据{case['jsonExData']}提取数据, 此时全局变量为: {dict}")


def jdbc_extractor(case,dict):
    if case["sqlExData"]:
        with allure.step("4.JDBC提取"):
             for key, value in eval(case["sqlExData"]).items():
                 result = send_jdbc_request(value)
                 dict[key] = result
             logging.info(f"4.JDBC提取, 根据{case['sqlExData']}提取数据, 此时全局变量为: {dict}")